<template>
	<view class="address-container">
		<view class="address-item" v-for="(item, index) in myaddress" :key="index">
			<view class="top">
				<view class="left">
					<view class="left-top">
						<view class="buyer-name">
							<!-- 小黑子 -->
							{{ item.buyerName }}
						</view>
						<view class="phone">
							<!-- 13094785088 -->
							{{ item.phone }}
						</view>
					</view>
					<view class="left-bottom">
						<!-- 广东省广州市海珠区新港中路397号 -->
						{{ item.buyerAddr }}
					</view>
				</view>
				<view class="right">
					<uni-icons type="compose" size="24"></uni-icons>
				</view>
			</view>
			<view class="bottom">
				<view class="left">
					<radio :checked="item.state" @click="radioClickHandler(item)"/>默认地址
				</view>
				<view class="right" @click="removeAddress(item)">
					删除
				</view>
			</view>
		</view>
		<view class="add-address" @click="addAddress">
			添加新地址
		</view>
	</view>
</template>

<script>
	import { mapMutations, mapState } from 'vuex'
	export default {
		data() {
			return {
				
			};
		},
		computed: {
			...mapState('module_user', ['myaddress'])
		},
		methods: {
			...mapMutations('module_user', ['updateMyAddressState', 'removeMyAddress']),
			addAddress() {
				uni.navigateTo({
					url: '/subcontract/update_address/update_address',
				})
			},
			radioClickHandler(item) {
				item.state = !item.state
				this.updateMyAddressState(JSON.parse(JSON.stringify(item)))
			},
			removeAddress(item) {
				uni.showModal({
					title: '提示',
					content: '是否删除',
					success: res => {
						if (res.confirm) {
							this.removeMyAddress(item)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.address-container {
	width: 100%;
	.address-item {
		width: 100%;
		padding: 20rpx;
		background-color: #fff;
		box-sizing: border-box;
		margin-bottom: 20rpx;
		.top {
			display: flex;
			padding-bottom: 20rpx;
			margin-bottom: 20rpx;
			justify-content: space-between;
			border-bottom: #f0f0f0 solid 1px;
		}
		.left-top {
			display: flex;
			align-items: center;
			margin-bottom: 20rpx;
			.buyer-name {
				font-size: 16px;
				font-weight: bold;
				margin-right: 20rpx;
			}
			.phone {
				font-size: 15px;
			}
		}
		.left-bottom {
			font-size: 14px;
		}
		.right {
			width: 10%;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.bottom {
			display: flex;
			font-size: 14px;
			justify-content: space-between;
		}
	}
}
.add-address {
	position: fixed;
	bottom: 0;
	left: 0;
	height: 50px;
	line-height: 50px;
	width: 100%;
	text-align: center;
	background-color: aqua;
	color: #fff;
}
</style>
